|
1
|
|
|
// //////////////////////////////////////////////////////////////////////////////////// |
|
2
|
|
|
// Copyright © 2017 TangDongxin |
|
3
|
|
|
// |
|
4
|
|
|
// Permission is hereby granted, free of charge, to any person obtaining |
|
5
|
|
|
// A copy of this software and associated documentation files (the "Software"), |
|
6
|
|
|
// To deal in the Software without restriction, including without limitation |
|
7
|
|
|
// The rights to use, copy, modify, merge, publish, distribute, sublicense, |
|
8
|
|
|
// And/or sell copies of the Software, and to permit persons to whom the |
|
9
|
|
|
// Software is furnished to do so, subject to the following conditions: |
|
10
|
|
|
// |
|
11
|
|
|
// The above copyright notice and this permission notice shall be included |
|
12
|
|
|
// In all copies or substantial portions of the Software. |
|
13
|
|
|
// |
|
14
|
|
|
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, |
|
15
|
|
|
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES |
|
16
|
|
|
// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. |
|
17
|
|
|
// IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, |
|
18
|
|
|
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, |
|
19
|
|
|
// TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE |
|
20
|
|
|
// OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
|
21
|
|
|
// //////////////////////////////////////////////////////////////////////////////////// |
|
22
|
|
|
|
|
23
|
|
|
function setPreviewColor (result) { |
|
24
|
|
|
|
|
25
|
|
|
console.log('load Color'); |
|
|
|
|
|
|
26
|
|
|
document.querySelector('#fontStyleLabel').style.fontFamily = result.fontStyle || 'Consolas'; |
|
27
|
|
|
document.querySelector('#fontSizeLabel').style.fontSize = result.fontSize || '14px'; |
|
28
|
|
|
document.querySelector('#bgColorLabel').style.backgroundColor = result.bgColor || '#FDF6E3'; |
|
29
|
|
|
document.querySelector('#intColorLabel').style.color = result.intColor || '#657A81'; |
|
30
|
|
|
document.querySelector('#strColorLabel').style.color = result.strColor || '#2AA198'; |
|
31
|
|
|
document.querySelector('#keyColorLabel').style.color = result.keyColor || '#B58900'; |
|
32
|
|
|
document.querySelector('#defaultColorLabel').style.color = result.defaultColor || '#586E75'; |
|
33
|
|
|
|
|
34
|
|
|
} |
|
35
|
|
|
|
|
36
|
|
|
function onError (error) { |
|
37
|
|
|
|
|
38
|
|
|
alert(`Error: ${error}`); |
|
|
|
|
|
|
39
|
|
|
|
|
40
|
|
|
} |
|
41
|
|
|
|
|
42
|
|
|
function saveOptions (e) { |
|
43
|
|
|
|
|
44
|
|
|
e.preventDefault(); |
|
45
|
|
|
browser.storage.local.set({ |
|
|
|
|
|
|
46
|
|
|
'bgColor': document.querySelector('#bgColor').value, |
|
47
|
|
|
'intColor': document.querySelector('#intColor').value, |
|
48
|
|
|
'strColor': document.querySelector('#strColor').value, |
|
49
|
|
|
'keyColor': document.querySelector('#keyColor').value, |
|
50
|
|
|
'defaultColor': document.querySelector('#defaultColor').value, |
|
51
|
|
|
'fontStyle': document.querySelector('#fontStyle').value, |
|
52
|
|
|
'fontSize': document.querySelector('#fontSize').value, |
|
53
|
|
|
'strLength': document.querySelector('#strLength').value, |
|
54
|
|
|
|
|
55
|
|
|
'strictOnly': document.querySelector('#strictOnly').checked, |
|
56
|
|
|
'hideDetails': document.querySelector('#hideDetails').checked, |
|
57
|
|
|
'dontBeatify': document.querySelector('#dontBeatify').checked, |
|
58
|
|
|
'isHighlight': document.querySelector('#isHighlight').checked, |
|
59
|
|
|
'isDebug': document.querySelector('#isDebug').checked, |
|
60
|
|
|
'isRelaxedJsonSupport': document.querySelector('#isRelaxedJsonSupport').checked, |
|
61
|
|
|
}); |
|
62
|
|
|
alert('Success'); |
|
|
|
|
|
|
63
|
|
|
browser.storage.local.get().then(setCurrentChoice, onError); |
|
64
|
|
|
|
|
65
|
|
|
} |
|
66
|
|
|
|
|
67
|
|
|
function setCurrentChoice (result) { |
|
68
|
|
|
|
|
69
|
|
|
console.log(result); |
|
|
|
|
|
|
70
|
|
|
document.querySelector('#bgColor').value = result.bgColor || '#FDF6E3'; |
|
71
|
|
|
document.querySelector('#intColor').value = result.intColor || '#657A81'; |
|
72
|
|
|
document.querySelector('#strColor').value = result.strColor || '#2AA198'; |
|
73
|
|
|
document.querySelector('#keyColor').value = result.keyColor || '#B58900'; |
|
74
|
|
|
document.querySelector('#defaultColor').value = result.defaultColor || '#586E75'; |
|
75
|
|
|
document.querySelector('#fontStyle').value = result.fontStyle || 'Consolas'; |
|
76
|
|
|
document.querySelector('#fontSize').value = result.fontSize || '14px'; |
|
77
|
|
|
document.querySelector('#strLength').value = result.strLength || '300'; |
|
78
|
|
|
|
|
79
|
|
|
document.querySelector('#strictOnly').checked = result.strictOnly || false; |
|
80
|
|
|
document.querySelector('#hideDetails').checked = result.hideDetails || false; |
|
81
|
|
|
document.querySelector('#dontBeatify').checked = result.dontBeatify || false; |
|
82
|
|
|
document.querySelector('#isHighlight').checked = result.isHighlight || false; |
|
83
|
|
|
document.querySelector('#isDebug').checked = result.isDebug || false; |
|
84
|
|
|
document.querySelector('#isRelaxedJsonSupport').checked = result.isRelaxedJsonSupport || false; |
|
85
|
|
|
|
|
86
|
|
|
setPreviewColor(result); |
|
87
|
|
|
|
|
88
|
|
|
} |
|
89
|
|
|
|
|
90
|
|
|
function restoreOptions () { |
|
91
|
|
|
|
|
92
|
|
|
browser.storage.local.get().then(setCurrentChoice, onError); |
|
|
|
|
|
|
93
|
|
|
|
|
94
|
|
|
} |
|
95
|
|
|
|
|
96
|
|
|
document.addEventListener('DOMContentLoaded', restoreOptions); |
|
97
|
|
|
document.querySelector('form').addEventListener('submit', saveOptions); |
|
98
|
|
|
|